﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Model;

namespace Aliyeye.Car.Net.WebService
{
    public class BaseWebService : System.Web.Services.WebService
    {
        /// <summary>
        /// 服务器保存的所有SoapHeader列表
        /// </summary>
        private static List<SoapHeaderClass> soapHeaderList = new List<SoapHeaderClass>();

        /// <summary>
        /// 当前SoapHeader
        /// </summary>
        public SoapHeaderClass soapHeader = new SoapHeaderClass();

        public void RefreshSoapHeaderList(SoapHeaderClass newSoapHeader)
        {
            foreach (var soapHeader in soapHeaderList)
            {
                if (soapHeader.UserID == newSoapHeader.UserID)
                {
                    soapHeader.SessionID = newSoapHeader.SessionID;
                    return;
                }
            }
            var soapHeaderToAdd = new SoapHeaderClass(newSoapHeader.UserID, newSoapHeader.SessionID, newSoapHeader.UserName, newSoapHeader.LoginTime);
            soapHeaderList.Add(soapHeaderToAdd);
        }

        public bool CheckSoapHeader(SoapHeaderClass newSoapHeader)
        {
            foreach (var soapHeader in soapHeaderList)
            {
                if (soapHeader.UserID == newSoapHeader.UserID)
                {
                    return (newSoapHeader.SessionID == soapHeader.SessionID);
                }
            }
            return false;
        }
    }
}